package com.example.shiro.controller;

import com.example.shiro.entity.Article;
import com.example.shiro.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/mg")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @RequestMapping("add")
    public String add(){
        Article a = new Article();
        a.setAuthor("1");
        a.setContent("14141q51");
        a.setTitle("hahah");
        a.setCreateDate(new Date());
        articleService.add(a);
        return "ok";
    }

    @RequestMapping("delete/{id}")
    public String delete(@PathVariable String id) {
        articleService.delete(id);
        return "ok";
    }

    @RequestMapping("list")
    public List<Article> list() {
        return articleService.list();
    }

    @RequestMapping("info/{id}")
    public Article info(@PathVariable String id) {
        return articleService.getById(id);
    }
}
